#!/bin/bash
MAJOR_VERSION=8
MINOR_VERSION=0
PATCH_VERSION=25
RELEASE=17
#REVISION="4733775f703"
REVISION=`date +%Y%m%d%H%M`
GLIBC=`ldd --version | grep ldd | tail -n 1 | awk '{print $NF}'`
ARCH=x86_64
OS="Linux"
PKG_NAME=GreatSQL-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}-${RELEASE}-${OS}-glibc${GLIBC}-${ARCH}
BASE_DIR=/usr/local/${PKG_NAME}
SRC_DIR=/opt
BOOST_SOURCE_DIR=boost_1_73_0
GREATSQL_SOURCE_DIR=greatsql-8.0.25-17
JOBS=`nproc`

if [ ${ARCH} = "x86_64" ] ; then
  CMAKE_EXE_LINKER_FLAGS=" -ljemalloc "
fi

cd ${SRC_DIR}/${GREATSQL_SOURCE_DIR} && \
rm -fr bld && \
mkdir bld && \
cd bld && \
cmake .. -DBOOST_INCLUDE_DIR=${SRC_DIR}/${BOOST_SOURCE_DIR} \
-DLOCAL_BOOST_DIR=${SRC_DIR}/${BOOST_SOURCE_DIR} \
-DCMAKE_INSTALL_PREFIX=${BASE_DIR} -DWITH_ZLIB=bundled \
-DWITH_NUMA=ON -DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS}" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_CONFIG=mysql_release \
-DWITH_TOKUDB=OFF -DWITH_ROCKSDB=OFF \
-DCOMPILATION_COMMENT="GreatSQL (GPL), Release ${RELEASE}, Revision ${REVISION}" \
-DMAJOR_VERSION=${MAJOR_VERSION} -DMINOR_VERSION=${MINOR_VERSION} -DPATCH_VERSION=${PATCH_VERSION} \
-DWITH_UNIT_TESTS=OFF -DWITH_NDBCLUSTER=OFF -DWITH_SSL=system -DWITH_SYSTEMD=ON \
-DWITH_COREDUMPER=0 \
&& make -j${JOBS} && make -j${JOBS} install
